/** ChickenWarrior, a Simple Java ME game developed in Gnu/Linux
  *  Copyright (C) <2008>  Maxin B. John <maxinbjohn@gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 3 of the License, or
  *  any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, see http://www.gnu.org/licenses
  *  or write to the Free Software Foundation,Inc., 51 Franklin Street,
  *  Fifth Floor, Boston, MA 02110-1301  USA
  * 
  */

package com;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.Random;

/**
 * @author maxin.john
 */
public class MyGameDesign {

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">                      
    private Image eggs;
    private Sprite MyEgg;
    public int MyEggseq001Delay = 200;
    public int[] MyEggseq001 = {68, 68, 68, 67, 67};
    private TiledLayer MyLayer;
    private Sprite Chicken;
    public int Chickenseq001Delay = 100;
    public int[] Chickenseq001 = {84, 85, 86, 87, 84};
    private Image chickens;
    private TiledLayer ChicLayer;
    private Sprite Egg;
    public int Eggseq001Delay = 200;
    public int[] Eggseq001 = {69, 69, 69, 69, 69};
    private Sprite MyChicken;
    public int MyChickenseq001Delay = 200;
    public int[] MyChickenseq001 = {0, 0, 5, 16, 21};
    //</editor-fold>                    
   /* public int canvasHeight=100;
    public int canvasWidth;*/
    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">                       
    //</editor-fold>                     

     

                      
     
    public void updateLayerManagerForMySky(LayerManager lm) throws java.io.IOException {                                              
        // write pre-update user code here
        int intervalMin = 10;
        int intervalMax = 100;
        int halfInterval = (intervalMin - intervalMax) / 2;
        int integerDisc = Integer.MAX_VALUE / halfInterval;
        Random r = new Random(System.currentTimeMillis());
        int randomNumber = r.nextInt();
        randomNumber = randomNumber / integerDisc;
        randomNumber = randomNumber + halfInterval;
        randomNumber = randomNumber <0 ? -1*randomNumber: randomNumber;
        getEgg().setPosition(randomNumber, 0);
        getMyChicken().setPosition(10,100);
        getMyChicken().setVisible(true);
        getEgg().setVisible(true);
        lm.append(getEgg());
        lm.append(getMyChicken());
        getChicLayer().setPosition(0, 0);
        getChicLayer().setVisible(true);
        lm.append(getChicLayer());
                                               
        // write post-update user code here
    }                                    
                                  
  

    public Image getChickens() throws java.io.IOException {                                 
        if (chickens == null) {                               
            // write pre-init user code here
            chickens = Image.createImage("/chickens.png");                                  
        }                                
        // write post-init user code here
        return this.chickens;                        
    }
                      

    public TiledLayer getChicLayer() throws java.io.IOException {                                 
        if (ChicLayer == null) {                               
            // write pre-init user code here
            ChicLayer = new TiledLayer(20, 20, getChickens(), 16, 16);                                 
            int[][] tiles = {
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52 },
                { 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52, 52 }
            };                               
            // write mid-init user code here
            for (int row = 0; row < 20; row++) {                                  
                for (int col = 0; col < 20; col++) {
                    ChicLayer.setCell(col, row, tiles[row][col]);
                }
            }
        }                                
        // write post-init user code here
        return ChicLayer;                        
    }
                      

    public Sprite getEgg() throws java.io.IOException {                                   
        if (Egg == null) {                                 
            // write pre-init user code here
            Egg = new Sprite(getChickens(), 16, 16);                                    
            Egg.setFrameSequence(Eggseq001);                                  
            // write post-init user code here
        }                         
        return Egg;
    }
                       

    public Sprite getMyChicken() throws java.io.IOException {                                   
        if (MyChicken == null) {                                 
            // write pre-init user code here
            MyChicken = new Sprite(getChickens(), 16, 16);                                    
            MyChicken.setFrameSequence(MyChickenseq001);                                  
            // write post-init user code here
        }                         
        return MyChicken;
    }
                       



}
